package yz.com.javautil.regex;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Administrator
 */
public class DealAddressStringUtil {
    public static void main(String[] args) {
        Map<String, Object> map = dealAddr("海航临空产业园1号库（汉北云仓）");
        System.out.println(map);
    }


    private static Map<String, Object> dealAddr(String addr) {
        String bracketRegex = "[(].*[)]|[【].*[】]|[（].*[）]|[{].*[}]|[〈].*[〉]|[<].*[>]|[「].*[」]";
        addr = addr.replaceAll(bracketRegex, "");


        String roadRegex = "(?<road>([\u4e00-\u9fa5]{2,6}(路|街|道|街坊|大街|大道)))?" +
                "(?<roadNo>.*[0-9０１２３４５６７８９一二三四五六七八九十A-Z]?(号|號|巷|弄|院|区|条|\\#院|\\#|号院|号大院))?" +
                "(?<houseNo>.*[一二三四五六七八九十0-9A-Z]?(园|栋|橦|幢|座|号楼|\\#楼?))?" +
                "(?<cellNo>.*[一二三四五六七八九十东西南北甲乙丙0-9A-Z]?(单元|门|梯|座))?" +
                "(?<floorNo>.*[一二三四五六七八九十东西南北甲乙丙0-9A-Z]?(层|楼))?" +
                "(?<roomNo>.*[一二三四五六七八九十东西南北甲乙丙0-9A-Z\\-]?(室|户)?)?";

        Map<String, Object> result = new HashMap<>(8);
        Matcher matcher = Pattern.compile(roadRegex).matcher(addr);
        if (matcher.find()) {
            result.put("road", matcher.group("road"));
            result.put("road_no", matcher.group("roadNo"));
            result.put("house_no", matcher.group("houseNo"));
            result.put("cell_no", matcher.group("cellNo"));
            result.put("floor_no", matcher.group("floorNo"));
            result.put("room_no", matcher.group("roomNo"));
        }
        return result;
    }
}
